package com.ityuwen.mengyagushi.album.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class RedisDistributedClient {

    @Autowired
    private RedisTemplate redisTemplate;

    private String uuid;

    public RedisDistributedClient() {
        this.uuid = UUID.randomUUID().toString();
    }

    public DistributedLock getLock(String lockName){

        return new DistributedLock(redisTemplate, lockName, uuid + ":" + Thread.currentThread().getId());
    }
}
